<template>
   <div>
        <el-form :model="model" label-wwarehouse_ididth="80px" :rules="rulesForm" ref="dataForm">
            <el-form-item label="库区编码" class="box-Input-mini" prop="locatioN_CODE">
                <el-input v-model="model.locatioN_CODE" placeholder="请输入库区编码" autocomplete="off"></el-input>
            </el-form-item>
            <el-form-item label="库区名称" prop="locatioN_NAME" class="box-Input-mini">
                <el-input v-model="model.locatioN_NAME " placeholder="请输入库区名称" autocomplete="off"></el-input>
            </el-form-item>
             <el-form-item label="面积"  class="box-Input-mini">
                <el-input v-model="model.area"  placeholder="请输入描述信息" autocomplete="off"></el-input>
            </el-form-item> 
            <el-form-item label="负责人"  class="box-Input-mini">
                <el-input v-model="model.creatE_BY"  placeholder="请输入描述信息" autocomplete="off"></el-input>
            </el-form-item>
            <el-form-item label="备注"  class="box-Input-mini">
                <el-input type="textarea" v-model="model.remark" placeholder="请输入内容" autocomplete="off"></el-input>
            </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
            <el-button  style="padding:10px 25px;margin-right:10px;" size="samll" @click="CloseDialog">取 消</el-button>
            <el-button style="padding:10px 25px;" size="samll" slot="reference" @click="save" type="primary">确 定</el-button>
        </div>
   </div>
</template>

<script>
export default {
    props:{
        model:{
            type:Object,
            require:true,
        },
        isUpdate:{
            type:Boolean,
            require:true,
        }
    },
    
    data(){
        return{
            rulesForm:{
                locatioN_CODE:[{ required : true, message:'请输入库区编码', trigger:'blur'}],
                locatioN_NAME:[{ required : true, message:'请输入库区名称', trigger:'blur'}],
            }
        }
    },
    methods:{
        CloseDialog(){
            this.$emit('CloseDialog');
        },
        DataBind(){
            this.$emit('DataBind');
        },
        save(){//新增或修改
            console.log(this.model)

            this.$refs.dataForm.validate((valid)=>{
                if(valid){
                    if(this.isUpdate){
                        this.$http.putForm('/api/Reservoir',{model:this.model})
                        .then(res =>{
                            console.log(res);
                            if(res.data.code == 200){
                                this.ShowMsg(res.data.msg,'success');
                                this.DataBind();
                                this.CloseDialog();
                            }
                        })
                        .catch(err =>{
                            this.ShowMsg(res.data.msg,'error');
                        })
                    }
                    else{
                        this.$http.postForm('/api/Reservoir',{model:this.model})
                        .then(res =>{
                            console.log(res);
                            if(res.data.code == 200){
                                this.ShowMsg(res.data.msg,'success');
                                this.DataBind();
                                this.CloseDialog();
                            }
                        })
                        .catch(err =>{
                            this.ShowMsg(res.data.msg,'error');
                        })
                    }
                }
                else{
                    this.ShowMsg('验证不通过','error');
                }
            })
        },
    }
    
}
</script>
